<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>教务系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../js/layui/css/layui.css" media="all">

    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<div class="demoTable" style="text-align:center">
    学号：
    <div class="layui-inline">
        <input class="layui-input" id="student_id" autocomplete="off">
    </div>
    姓名：
    <div class="layui-inline">
        <input class="layui-input" id="student_name" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload">搜索</button>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="student_add">添加</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="../js/layui/layui.js" charset="utf-8"></script>
<script src="/js/layui/jquery.1.12.4.js" charset="utf-8"></script>
<script src="../js/layui/cookieutils.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#test'
            , url: '/admin/classInfo/select'
            , toolbar: '#toolbarDemo'
            , title: '教室信息表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: 'ID', width: 80, fixed: 'left', unresize: true, sort: true}
                , {field: 'studentname', title: '学生姓名', width: 120}
                , {field: 'rubandate', title: '入班时间', width: 120}
                // , {field: 'reason', title: '处分原因', width: 300}
                // , {field: 'joinTime', title: '加入时间', width: 120}
                /* ,{field:'email', title:'邮箱', width:150, edit: 'text', templet: function(res){
                         return '<em>'+ res.email +'</em>'
                     }}*/
                /* ,{field:'sex', title:'性别', width:80, edit: 'text', sort: true}*/

                // ,{field:'experience', title:'积分', width:80, sort: true}
                // ,{field:'ip', title:'IP', width:120}
                // ,{field:'logins', title:'登入次数', width:100, sort: true}
                // ,{field:'joinTime', title:'加入时间', width:120}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100}
            ]]
            , page: true
            , id: 'testReload'
        });

        var $ = layui.$, active = {
            reload: function () {
                var demoReload = $('#demoReload');

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        id: '' ? '' : $('#student_id').val(),
                        studentName: '' ? '' : $('#student_name').val()
                    }
                }, 'data');

            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            if (!isNaN($('#student_id').val()) && $('#student_name').val().length < 5) {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            } else {

                    layer.msg("学号或者姓名填写错误");

            }

        })
        ;

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
           if (obj.event==='student_add'){
               //window.open('');
                //Cookie的键必须换
               var access_token = getCookie("classInfo");

               window.location.href="/all?"+"banciId="+access_token;
           }


        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {

                layer.confirm('真的删除行么', function (index) {

                    $.ajax({
                        type: "POST",
                        url: "/admin/teacherInfo/del",
                        data: {id: data.id},
                        success: function (msg) {
                            layer.close(index);
                        }
                    });
                });
            }
        });
    })
    ;
</script>
<div id="add-main" style="display: none;">
    <form class="layui-form" id="add-form" action="" method="post">
        <div class="layui-form-item center">
            <label class="layui-form-label" style="width: 100px">学生姓名：</label>
            <div class="layui-input-block">
                <input type="text"  name="name" id="studentName" style="width: 240px" lay-verify="required"
                       placeholder="请填写学生姓名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">入班时间：</label>
            <div class="layui-input-block">
                <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                    <input type="text" class="layui-input" id="test1" style="width: 240px"  placeholder="请填写学生入学时间">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
<#--                <button class="layui-btn" lay-submit lay-filter="save" onclick="f();">立即提交</button>-->
                <input class="layui-btn" lay-sumit lay-filter="save" onclick="f()" value="提交">
            </div>
        </div>
    </form>
    <script type="text/javascript">
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#test1' //指定元素
            });
        });
        function f() {
            $.ajax({
                type: "POST",
                url: "/admin/student_add",
                data: {student_name: $('#studentName').val(),student_times: $('#test1').val()},
                success: function (msg) {
                    layer.close(index);
                }
            });
        }
    </script>
</div>

</div>


</body>
</html>
</div>
</body>
</html>
